Component({
    options: {
        multipleSlots: true // 在组件定义时的选项中启用多slot支持
    },
    properties: {
        //由上层组件传递过来的数据
        swipeData: {
            type: Object,
            default: [],
            style: 0,
        }
    },

    data: {
        startX: null,
        moveX: null,
        isVip:true,
    },
    onLoad() {
        this.data.swipeData.style = 0;
    },

    methods: {
        ts(e) {
            if (e.touches.length === 1) {
                this.startX = e.touches[0].clientX;
                this.moveX = e.touches[0].clientX;
                if(this.data.swipeData.style == null){
                    this.data.swipeData.style = 0;
                }
            }
        },
        tm(e) {
           
            if (e.touches.length === 1) {
                // 手指起始点位置与移动期间的差值
                var distenceX = this.moveX - e.touches[0].clientX
                this.moveX = e.touches[0].clientX;

                if ((this.data.swipeData.style - distenceX) < -200) {
                    this.data.swipeData.style = -200
                } else if ((this.data.swipeData.style - distenceX) > 0) {
                    this.data.swipeData.style = 0
                } else {
                    this.data.swipeData.style = this.data.swipeData.style - distenceX
                    
                }
                this.setData({
                    swipeData: this.data.swipeData
                })
            }
        },

        te(e) {
           
            if (e.changedTouches.length === 1) {
                if (this.data.swipeData.style <= -100) {
                    this.data.swipeData.style = -200
                } else {
                    this.data.swipeData.style = 0
                }
                this.setData({
                    swipeData: this.data.swipeData
                })
            }
        },
        handleRightBtnTap(e) {
            var item = e.currentTarget.dataset.swipedata;
            item = JSON.parse(JSON.stringify(item))
            delete item.style
            this.triggerEvent('delItem', item);
            // this.$emit('delItem', )
        },
        handleClickBtnTap(e){
            
            var item = e.currentTarget.dataset.swipedata;
            item = JSON.parse(JSON.stringify(item))
            // delete item.style
            this.triggerEvent('clickItem', item);
        }
    }
})